@include('Home.head')
<body>
<div class="container" id="app">
    @include('Home.member.header')
    <div class="my-nav-bar">
        <ol class="am-breadcrumb">
            <li><a href="#">首页</a></li>
            <li><a href="#">升级为商家</a></li>
        </ol>
    </div>
    <div class="cart-panel">
        <div class="withdrawals-panel">
            <form class="am-form">
                <div class="am-form-group">
                    <h3>币种</h3>
                    复投币余额：<span class="red">￥{{ Session::get('home_user')->credit6}}</span>
                </div>
            </form>
        </div>
        <div class="withdrawals-panel"><span class=" red2">*</span>所需费用：<span class="red2">￥3018</span>（含运费）</div>
        {{--<div class="withdrawals-panel"><span class=" red2">*</span>所需运费：<span class="red2">￥18</span></div>--}}
        <div class="my-search-title-panel">
        <p class="my-search-titp-p am-text-sm bold">冷敷贴</p>
            <!-- <p class="my-search-titp-p am-text-sm bold">百草液</p> -->
            <div style="overflow:hidden">
                <form class="am-form-inline" role="form">
                    <button type="button" class="am-btn am-btn-default" style="float:left" v-on:click="stickMinus()"><i class="am-icon-minus"></i></button>
                    <input type="number" name="txtQty" v-model="user.stick" disabled="disabled" class="am-form-field txt-qty am-text-center am-text-sm" style=" width:60px; margin-right:0px; height:40px; display:inline; float:left">
                    <button type="button" class="am-btn am-btn-default" style="float:left" v-on:click="stickAdd()"><i class="am-icon-plus"></i></button>
                </form>
            </div>
            <p class="my-search-titp-p am-text-sm bold">百草液</p>
            <div style="overflow:hidden">
                <form class="am-form-inline" role="form">
                    <button type="button" class="am-btn am-btn-default" style="float:left" v-on:click="liquidMinus()" ><i class="am-icon-minus"></i></button>
                    <input type="number" name="txtQty" v-model="user.liquid" disabled="disabled" class="am-form-field txt-qty am-text-center am-text-sm" style=" width:60px; margin-right:0px; height:40px; display:inline; float:left">
                    <button type="button" class="am-btn am-btn-default" style="float:left" v-on:click="liquidAdd()"><i class="am-icon-plus"></i></button>
                </form>
            </div>
        </div>
        <div class="partners-title-panel" >
            <div class="partners-title-panel-title" v-if="address != ''" style="height: 80px;padding-left: 10px;">
                @{{ address.name }}  &nbsp;@{{ address.phone }} <a href="/home/member/addresslist" v-show="address.default" style="color: red;float: right;margin-right: 20px">修改地址</a><br>
                <a style="width:100%;height:49px;font-size: 12px;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">@{{ address.province }}@{{ address.city }}@{{ address.district }}@{{ address.address }}</a>
            </div>
            <div  v-if="address == ''">
                <p class="am-text-center" onclick="window.location.href='/home/member/address'"><button type="button" class="am-btn am-btn-default am-radius am-btn-block" >添加收货地址</button></p>
            </div>
        </div>
        {{--<div class="withdrawals-panel"><span class=" red2">*</span>所需费用：<span class="red2">￥@{{user.rulingprice}}</span></div>--}}
        {{--<div class="am-checkbox">--}}
            {{--<label>--}}
                {{--<input type="checkbox"> 我已阅读并同意<a href="#">《协议》</a>--}}
            {{--</label>--}}
        {{--</div>--}}
        <p class="am-text-center"><button type="button" v-if="status == 0" v-on:click="add()" class="am-btn am-btn-danger am-radius">立即复投</button></p>
        <p class="am-text-center"><button type="button" v-if="status == 1" class="am-btn am-btn-danger am-radius" disabled="disabled">支付中..</button></p>
    </div>
    <!--底部-->
    @include('Home.foot')
</div>
</body>
<script src="{{ URL::asset('js/address/distpicker.data.js') }}"></script>
<script src="{{ URL::asset('js/address/distpicker.js') }}"></script>
<script src="{{ URL::asset('js/address/main.js') }}"></script>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            title: '直商城复投',
            user:{
                rulingprice:0,
                goodsid:0,//商品id
                stick:10, //冷敷贴
                liquid:0, //百草液
                addressid:0,
            },
            rulingprice:30,
            address:'',
            goodsNum:10, //商品的总共数量
            status:0,
        },
        methods: {
            //获取url
            obtain:function (val) {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i=0;i<vars.length;i++) {
                    var pair = vars[i].split("=");
                    if(pair[0] == val){
                        return pair[1];
                    }
                }
            },
            initialize:function () {
                $.post("/home/member/addaddress",{'_token':'{{csrf_token()}}',class:'find'},function (res) {
                    if (res.code) {
                        var level =  "{{ Session::get('home_user')->level }}";
                        if(level == 2){
                            app.rulingprice = 20
                        }
                        app.address = res.data
                        app.user.addressid = res.data.id
                    } else {
                        layer.msg(res.data);
                    }
                });
            },
            level:function (val,index) {
                app.user.goodsid = index
                app.goodsNum = val;
                app.user.stick = parseInt(val);
                app.user.liquid = 0;
                // app.user.liquid = parseInt(val.straight / 2);
            },
            stickAdd:function () { //加冷敷贴
                if( app.user.stick >= app.goodsNum ) {
                    layer.msg('超出了范围');return;
                }
                app.user.stick = app.user.stick+1;
                app.user.liquid = app.user.liquid-1;
            },
            stickMinus:function () { //减
                if(app.user.stick <= 0) {
                    layer.msg('超出了范围');return;
                }
                app.user.stick -= 1;
                app.user.liquid += 1;
            },
            liquidAdd:function () { //加冷敷贴
                if( app.user.liquid >= app.goodsNum) {
                    layer.msg('超出了范围');return;
                }
                app.user.liquid = app.user.liquid+1;
                app.user.stick = app.user.stick-1;
            },
            liquidMinus:function () { //减
                if(app.user.liquid <= 0) {
                    layer.msg('超出了范围');return;
                }
                app.user.stick += 1;
                app.user.liquid -= 1;
            },
            add:function () {
                if(app.goodsNum == 0){
                    layer.msg('请选择升级产品');return;
                }
                if(app.address == ''){
                    layer.msg('请选择收货地址');return;
                }
                if(app.status == 0){
                    app.status = 1;
                    layer.load(2);
                    $.post("/home/voting/votings",{'_token':'{{csrf_token()}}',users:app.user},function (res) {
                        layer.closeAll('loading');
                        if (res.code) {
                            layer.msg(res.data,{time:500},function () {
                                window.location.href="/home/member/index";
                            });
                        } else {
                            app.status = 0;
                            layer.msg(res.data);
                        }
                    });
                } else {
                    layer.msg('支付中...');return;
                }

            }
        },
        //自动执行
        mounted: function () {
            this.initialize();
        },
    })
</script>
</html>
